<template>
<div>
  <div class="nav">
    <nav><p><b v-for="(item,index) in newsList" :key="index" @click="getid(item)">{{item.name}}</b></p></nav>
    <router-link to="/newsList"><div><a-icon type="menu-unfold" /></div></router-link>
  </div>
  <van-pull-refresh v-model="isLoading" @refresh="onRefresh" class="content">
    <slideshow></slideshow>

      <ul class="ul">
        <li v-for="(item,index) in list" :key="index" class="list">
          <router-link :to="{path:'/newsDetail',query:{articleId:item.articleId}}" class="link">
            <div class="pic">
              <img v-lazy="item.bannerImgUrl" alt="">
            </div>
            <div class="text">
              <p>{{item.title}}</p>
              <span>{{item.articleSource}}</span><br>
              <span>{{item.sendTime}}</span>
            </div>
          </router-link>

        </li>
      </ul>
  </van-pull-refresh>
</div>
</template>

<script>
import {Toast} from 'vant'
// Vue.use(Lazyload, {
//   lazyComponent: true,
// })
import slideshow from "@/components/slideshow";
import {newDetail} from "../api/api"
export default {
name: "newsDetail",
  components:{
    slideshow
  },
  data(){
    return{
      list:[],
      newsList:[],
      id:'',
      isLoading: false,
      imageList: []
    }
  },
  created() {
    this.newsList = this.$store.state.newList
    newDetail().then(res=>{
      console.log(res)
      this.list = res.rows
      // for(let i = 0; i<this.list.length;i++){
      //   this.imageList.push(this.list[i].bannerImgUrl)
      // }
      // console.log(this.imageList)
    })
  },
  computed:{
    // NewsId(){
    //   return this.$store.state.NewsId
    // }
    // imageList(){
    //   return this.list
    // }
  },
  methods:{
    onRefresh() {
      setTimeout(() => {
        Toast('刷新成功');
        this.isLoading = false;
        this.count++;
      }, 1000);
    },
    getid(item){
      this.id=item.categoryId
      console.log(this.id)
      // this.$store.commit('changNewsId',item.categoryId)
      // console.log(this.$store.state.NewsId)
      newDetail(this.pageNum=1,this.pageSize=18,this.categoryId=this.id).then(res=>{
        console.log(res)
        this.list = res.rows
      })
    },
  },
}
</script>

<style scoped lang="less">
*{
  padding: 0;
  margin: 0;
}
.content{
  overflow: auto;
  height: calc(100vh - 160px);
}
.ul{
  height: auto;
  //overflow: auto;
  background-image: url("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3703799948,3123288320&fm=26&gp=0.jpg");
}
.list{

  .link{
    width: 100%;
    height: 100px;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    .pic{
      width: 30%;
      height: 100%;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .text {
      width: 70%;
      margin-left: 20px;
      p{
        color: black;
        font-size: 14px;
      }
      span{
        color: #777;
        //display: inline-block;
        font-size: 12px;

      }
    }
  }

}
.nav{
  height: 30px;
  font-size: 20px;
  padding-left: 20px ;
  display: flex;
  justify-content: space-between;
  //h2{
  //  margin-left: 50px;
  //}
  nav{
    width: 86%;
    overflow: auto;

    p{
      white-space: nowrap;
      b{
        font-size: 16px;
        margin-right: 8px
      }
    }

  }
  div{
    box-shadow: 2px 2px 5px #ccc;
  }
}
</style>